package tr.edu.metu.is.mega.server.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * Singleton utility class for entity management.
 */
public final class EntityManagerUtil {

    private static EntityManagerUtil instance = null;

    private final EntityManagerFactory emf;

    /**
     * Default constructor.
     */
    private EntityManagerUtil() {
        emf = Persistence.createEntityManagerFactory("MEGAPU");
    }

    public static EntityManagerUtil getInstance() {
        if (instance == null) {
            instance = new EntityManagerUtil();
        }
        return instance;
    }

    /**
     * Creates and returns an entity manager instance.
     * 
     * @return entity manager instance
     */
    public EntityManager createEntityManager() {
        return emf.createEntityManager();
    }
}
